public class Solution1526 {
    public int minNumberOperations(int[] target) {
        int last=0,ans=0;
        for (int i=0;i<target.length;i++){
            while (i+1<target.length && target[i]<=target[i+1]){
                i++;
            }
            ans+=target[i]-last;
            while (i+1<target.length && target[i]>=target[i+1]){
                i++;
            }
            last=target[i];
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1526().minNumberOperations(new int[]{1,2,3,2,1}));
    }
}
